﻿using System;
using System.Collections.Generic;
using System.Linq;
using Luna.Data.CRM;

namespace Luna.Model.CRM
{
    internal class Account : LunaReferenceEntity<IAccountData>, IAccount
    {
        public Account(IAccountData data)
            : base(data)
        {
        }

        protected Account()
        {
        }

        protected Account(Account account)
            : base(account)
        {
        }

        public IEnumerable<IContact> Contacts
        {
            get
            {
                return DataModel.Contacts.ContactGetAllByAccount(this.Data).Select(x => new Contact(x));
            }
        }

        public ICategory Category
        {
            get { return GetEntity(ApplicationModel.CRM.Categories, Data.CategoryID); }
        }

        public string Name
        {
            get { return Data.Name; }
        }

        public string Address
        {
            get { return Data.Address; }
        }

        public string ZipCode
        {
            get { return Data.ZipCode; }
        }

        public string City
        {
            get { return Data.City; }
        }

        public string Country
        {
            get { return Data.Country; }
        }

        public Uri Url
        {
            get { return new Uri(Data.Url); }
        }

        public string Comment
        {
            get { return Data.Comment; }
        }

        public IEditableAccount EditableCopy
        {
            get { return new EditableAccount(this); }
        }
    }
}